package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	r.GET("/hello", func(c *gin.Context) {
		c.String(http.StatusOK, "hello world")
	})
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "pong",
		})

	})
	r.GET("/user/:name", func(c *gin.Context) {
		name := c.Param("name")
		c.String(http.StatusOK, "hello %s", name)
	})
	r.GET("/view/*.html", func(c *gin.Context) {
		c.String(http.StatusOK, "hello view")
	})
	r.GET("/order", func(c *gin.Context) {
		oid := c.Query("id")
		c.String(http.StatusOK, "hello %s", oid)
	})
	r.POST("/ping", func(c *gin.Context) {
		c.String(http.StatusOK, "hello post 方法")
	})
	err := r.Run(":8080")
	if err != nil {
		return
	}
}
